var BaseDao = require("../../base-dao/BaseDao");


//景区列表
exports.sceniclist = function (callback) {
    var sql = "select * from tbl_sceniclist where status=1";
    BaseDao.execQuery(sql, function (err, rows1) {
        callback(err, rows1);
    })
}

//景区商品列表

exports.shoplist = function (sid,callback) {
    var sql="select d.*,g.type from tbl_gooddetail d left join " +
        "tbl_goods g on d.goodid = g.id " +
        "where d.status=1 and g.status=1 and d.spotid='"+sid+"' order by d.createAt DESC";
    BaseDao.execQuery(sql,function (err,datas) {
        callback(err,datas);
    })
}

//添加景点
exports.addsceniclist = function (obj, callback) {
    var sql = 'INSERT INTO tbl_sceniclist SET ?';
    BaseDao.execQuery(sql, obj, function (err, data) {
        callback(err, data);
    })
}

//添加商品信息
exports.addticketlist = function (obj, callback) {
    var sql = 'INSERT INTO tbl_goods SET ?';
    BaseDao.execQuery(sql, obj, function (err, data) {
        callback(err, data);
    })
}

//获取票的详情信息
exports.ticketdetail = function (id, callback) {
    var c = '';
    if (id) {
        c = ' and d.id="' + id + '" ';
    }
    var sql="select d.*,g.type from tbl_gooddetail d left join " +
        "tbl_goods g on d.goodid = g.id " +
        "where d.status=1 and g.status=1 "+c+" order by d.createAt DESC";
    BaseDao.execQuery(sql, function (err, data) {
        callback(err, data);
    })
}

//确认预定后保存预定商品信息
exports.reservemessage = function (obj, callback) {
    var sql = "INSERT INTO tbl_perorder SET ?";
    BaseDao.execQuery(sql, obj, function (err, data) {
        callback(err, data)
    })
}

//更新订单信息
exports.updatereservemes = function (userid, id, payment, callback) {
    var sql = 'UPDATE tbl_pay SET payment="' + payment + '",ispayment=1 WHERE id ="' + id + '" and status=1';
    console.log(sql);
    BaseDao.execQuery(sql, function (err, data2) {
        var sql2 = 'UPDATE tbl_perorder SET orderstatus=1  WHERE payid ="' + id + '" and status=1';
        console.log(sql2);
        BaseDao.execQuery(sql2, function (err, data) {
            callback(err, {data2:data2,data:data})
        })
    })
}

//加入购物车
exports.savetocart = function (obj, callback) {
    var sql = "INSERT INTO tbl_cart SET ?";
    BaseDao.execQuery(sql, obj, function (err, data) {
        callback(err, data)
    })
}

//单个商品预定支付成功
exports.onlyreserve = function (obj, callback) {
    var sql = "INSERT INTO tbl_pay SET ?";
    BaseDao.execQuery(sql, obj, function (err, data) {
        callback(err, data)
    })
}

exports.upstatus = function (obj, callback) {
    var sql = "update tbl_perorder set orderstatus=3 where status=1 and orderno='" + obj.orderno + "'";
    BaseDao.execQuery(sql, function (err, data) {
        callback(err, data)
    })
}